#!/usr/bin/python



from xpcom import *
import sys

import logging
logger = logging.getLogger("the_nepomuk_whisperer")


# This class is the entry point for the XUL pages. It provides some constants (NAO, PIMO) that will be used by the XUL pages to call the methods from one ontology or the other.

class TheNepomukWhisperer(object): # Inherits from object
	
	#~~~~~~~~~~~~~~~~~~~~~~~~~ BEGIN  ~~~~~~~~~~~~~~~~~~~~~~~~~#
	
	#~ This is the Python code for an advanced Singleton Design Pattern use. ~#
	#~ see http://en.wikipedia.org/wiki/Singleton_pattern#Python for more information (available on the 2008-07-07). ~#
	#~ If you want to inherit from TheNepomukWhisperer, you should study the subject and possibly rewrite it (see the same web page for details on inheritance). ~#
	
	# static attributes of the class Interface
	instance = None
	
	# standard construction method in Python
	def __new__(theNepomukWhispererClass, current_url, results_path, service_name="org.kde.NepomukStorage", model_name="/org/soprano/Server/models/main"):
		# may raise a dbus.exceptions.DBusException if the org.kde.NepomukStorage is not accessible (exception raised by python_interface_to_soprano.py)
		
		logger.debug("TheNepomukWhisperer.__new__")
		if theNepomukWhispererClass.instance is None:
			
			# initializations (run only once)
			logger.debug("\t(first time)")
			
			self_obj = object.__new__(theNepomukWhispererClass)
			theNepomukWhispererClass.instance = self_obj
			
			# interface
			from python_interface_to_soprano import Interface
			self_obj.interface = Interface(results_path, service_name, model_name)
			
			# nao
			from nao import Nao
			self_obj.nao = Nao(self_obj.interface)
			
			#pimo
			from pimo import Pimo
			self_obj.pimo = Pimo(self_obj.interface)
			
		return theNepomukWhispererClass.instance
		
		# TODO: add an assertion? (see given web page)
	
	#~~~~~~~~~~~~~~~~~~~~~~~~~  END   ~~~~~~~~~~~~~~~~~~~~~~~~~#
	
	
	def __init__(self, current_url, results_path, service_name="org.kde.NepomukStorage", model_name="/org/soprano/Server/models/main"):
		
		logger.debug("TheNepomukWhisperer.__init__")
		self.current_url = current_url






logger.debug("the_nepomuk_whisperer.py has been imported")